package algorithm.sort;

import java.util.Arrays;

/**
 * @ClassName SelectSort
 * @Author 刘正星
 * @Date 2021/6/19 下午3:53
 * @Description
 */
public class SelectSort {

    public static int[] seletSort(int[] arr){
        int minIndex,temp;
        for (int i = 0; i < arr.length-1 ; i++) {
             minIndex = i;
            for (int j = i+1; j <arr.length ; j++) {
                if (arr[j]<arr[minIndex]){
                    minIndex = j;
                }
            }

            temp = arr[i];
            arr[i] = arr[minIndex];
            arr[minIndex] = temp;

        }


        return arr;
    }

    public static int[] insertSort(int[] arr){

        for (int i = 0; i < arr.length - 1 ; i++) {

            int temp = arr[i+1];

            for (int j = i; j >= 0 ; j--) {
                if (arr[j]>temp){
                    int re = arr[j];
                    arr[j] = temp;
                    arr[j+1] = re;
                }

            }

        }
        return arr;
    }

    public static void main(String[] args) {
        int [] arrs =  {1,2,5,6,3,12,7,4,30,24};
        int[] ints = insertSort(arrs);
        System.out.println(Arrays.toString(ints));
    }
}
